package org.qqcui.designpattern.patterns.adapter.object;

/**
 * 将220V交流电转换为5V直流电的适配器类
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022/4/28 16:45
 **/
public class VoltageAdapter implements IVoltage5V {

    private Voltage220V voltage220V;

    public VoltageAdapter(Voltage220V voltage220V) {
        this.voltage220V= voltage220V;
    }

    @Override
    public int output5v() {
        int dst = 0;
        if (voltage220V != null) {
            // 获得交流电的电压
            int src = voltage220V.output220v();
            // 通过硬件降压为5V直流电
            dst = src / 44;
            System.out.println("降压为：" + dst +"V直流电");
        }
        return dst;
    }
}
